<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = [
        [1, 2, 3, 4], // 0,3
        [4, 2, 5, 1], // 1,2
        [9, 4, 3, 4], // 2,1
        [1, 8, 3, 6], // 3,0
      ];

      function sum(arr) {
        let r = 0;
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].length; j++) {
            if (i === j || i + j === arr[i].length - 1) {
              r += arr[i][j];
            }
          }
        }
        return r;
      }

      console.log(sum(arr));
    </script>
  </body>
</html>
